<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ page isELIgnored="false"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">

<html>
<head>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" media="screen"
		href="<s:url value="/resources"/>/css/zTreeStyle/zTreeStyle.css"
		type="text/css">
		<link rel="stylesheet" type="text/css" media="screen"
			href="<s:url value="/resources"/>/css/zTreeStyle/demo.css"
			type="text/css">
			<link rel="stylesheet" type="text/css" media="screen"
				href="<s:url value="/resources"/>/css/innerstyle.css"
				type="text/css" />
			<link rel="stylesheet" type="text/css" media="screen"
				href="<s:url value="/resources"/>/css/ui-lightness/jquery-ui-1.8.23.custom.css" />
			<script type="text/javascript"
				src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
			<script type="text/javascript"
				src="<s:url value="/resources"/>/js/jquery-ui-1.8.23.custom.min.js"></script>
			<script type="text/javascript"
				src="<s:url value="/resources"/>/js/jquery.ztree.all-3.4.min.js"></script>
			<style type="text/css">
#but1 {
	position: relative;
	right: 0px;
	top: 153px;
	text-align: center;
}

#but2 {
	position: relative;
	right: 0px;
	top: 173px;
	text-align: center;
}
</style>
			<SCRIPT type="text/javascript">		var setting = {
			edit: {
				enable: false,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			  data: {
			simpleData: {
				enable:true,
				idKey: "jiesdwbm",
				pIdKey: "pid",
				rootPId: ""
			}
		},
			callback: {			    
				beforeDrag: false,
				beforeDrop: false,
				onDblClick: zTreeOnDblClick
				
			}
		};
function zTreeOnDblClick(event, treeId, treeNode) {
   // alert(treeNode ? treeNode.tId + ", " + treeNode.name : "isRoot");
    //alert(treeId);
    if(treeId=='treeDemo'){	
		save(treeNode.id);       	
		}else{
		remove(treeNode.id); 
		}	
};


		function beforeDrag(treeId, treeNodes) {
			for (var i=0,l=treeNodes.length; i<l; i++) {
			    //alert(treeNodes[i].pId);
				if (treeNodes[i].drag === false) {
					return false;
				}
			}
			return true;
		}
		function beforeDrop(treeId, treeNodes, targetNode, moveType) {
		    //alert(treeNodes[0].name);
			return targetNode ? targetNode.drop !== false : true;
		}
		
		function chickDrop(treeID,type){		
		var treeObj = $.fn.zTree.getZTreeObj(treeID);		
		var sNodes = treeObj.getSelectedNodes();       
	    var tId = sNodes[0].tId;
        var node = treeObj.getNodeByTId(tId);   

		if(type=='1'){	
		save(node.id);       	
		}else{
		remove(node.id); 
		}				
		}
		
		function save(nodeid){		    
		    var url = "addUserFhdw?leix=13&nodeid="+nodeid;		    
		    $.post(url, function(data) {
              alert(eval('(' + data + ')').msg);
               new_data();
            });
		}
		
		function remove(nodeid){
		   var url = "delUserFhdw?leix=13&nodeid="+nodeid;		   
		    $.post(url, function(data) {
               alert(eval('(' + data + ')').msg);
               new_data();
            });
		}
		
		function old_data(){
		$.ajax({
             type: "post",
             dataType:'text',
             //dataType: "json",//返回json格式的数据
             url: "findJsdwList",
             success: function(data){
                 var zNodes = data;                 
                 $.fn.zTree.init($("#treeDemo"), setting, eval('(' + zNodes + ')')); 
                }  
              });
		
		}
		
		function new_data(){
		$.ajax({
             type: "post",
             dataType:'text',             
             url: "findUserFhdw?leix=13",
             success: function(data){
                 var zNodes = data;
                 $.fn.zTree.init($("#treeDemo2"), setting, eval('(' + zNodes + ')')); 
                }  
              });
		}
		/*初始化*/
		$(function(){
		    $("#but1").button(); 
            $("#but2").button();
		    old_data();
            new_data();
		});
		
		/*搜索ztree*/
		function searchZtree(){		    
            //alert("aa");
             var jsdwmc =  encodeURI($("#jsdwmc").val());             
             var url = "findJsdwList?nodeid="+jsdwmc;                    
             $.post(url,function(data) {
               var zNodes = data;                              
               $.fn.zTree.init($("#treeDemo"), setting, eval('(' + zNodes + ')'));              
            });
		}
		</SCRIPT>
</HEAD>


<body>
	<div id="best1">
	
		<div >
			<font color="red">左侧窗口为被选项，右侧窗口为定制项，通过点击中间按钮或双击鼠标左键操作</font>
		</div>
		<div class="content_wrap">

			<div class="zTreeDemoBackground left">
				<ul class="list">
					<li class="title">结算单位：<input id="jsdwmc" type="text"
						style="width:310px;" /> &nbsp;<a id="menuBtn" href="#"
						onclick="searchZtree();">查询</a>
					</li>
				</ul>
				<ul id="treeDemo" class="ztree"></ul>
			</div>

			<div class="center">
				<input type="button" id="but1" value=">"
					onclick="chickDrop('treeDemo','1');" /> <br> <input
					type="button" id="but2" value="<" onclick=" chickDrop('treeDemo2','2');"/>
			</div>

			<div class="right">
				<ul>&nbsp;
				</ul>
				<ul id="treeDemo2" class="ztree"></ul>
			</div>
			<div></div>

		</div>
		
		<br class="spacer" />

	</div>
</body>
</html>
